include_directories(${DRM_INCLUDE_DIRS})

add_library(
  mirconsole OBJECT

  linux_virtual_terminal.cpp                linux_virtual_terminal.h
  logind_console_services.cpp               logind_console_services.h
  minimal_console_services.h                minimal_console_services.cpp
  logind-seat.c                             logind-seat.h
  logind-session.c                          logind-session.h
  default_configuration.cpp
  ioctl_vt_switcher.cpp                     ioctl_vt_switcher.h)

set_source_files_properties(
  logind-seat.c
  logind-seat.h
  logind-session.c
  logind-session.h

# There's no need to warn about things in the autogenerated files we can't fix
  PROPERTIES
  COMPILE_FLAGS
    "${CMAKE_C_FLAGS} -Wno-pedantic -Wno-unused-parameter -Wno-unused-function"
)

target_link_libraries(mirconsole
  PUBLIC
    mirplatform
    mircommon
    mircore
)

set_property(
    SOURCE logind_console_services.cpp default_configuration.cpp
    PROPERTY COMPILE_OPTIONS -Wno-variadic-macros)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/logind-seat.h
  COMMAND
    gdbus-codegen
    --header
    --output logind-seat.h
    --interface-prefix org.freedesktop.login1
    --c-namespace Logind
    ${CMAKE_CURRENT_SOURCE_DIR}/logind-seat.xml
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/logind-seat.c
  COMMAND
    gdbus-codegen
    --body
    --output logind-seat.c
    --interface-prefix org.freedesktop.login1
    --c-namespace Logind
    ${CMAKE_CURRENT_SOURCE_DIR}/logind-seat.xml
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/logind-session.h
  COMMAND
    gdbus-codegen
    --header
    --output logind-session.h
    --interface-prefix org.freedesktop.login1
    --c-namespace Logind
    ${CMAKE_CURRENT_SOURCE_DIR}/logind-session.xml
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/logind-session.c
  COMMAND
    gdbus-codegen
    --body
    --output logind-session.c
    --interface-prefix org.freedesktop.login1
    --c-namespace Logind
    ${CMAKE_CURRENT_SOURCE_DIR}/logind-session.xml
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
